package testtiles;

import java.awt.Color;
import java.awt.Graphics2D;

import testtiles.object.UIWorld;
import testtiles.object.Unit;
import testtiles.object.UnitTemplate;
import butines.core.game.Drawing;
import butines.core.game.Game;
import butines.core.game.GameContainer;
import butines.core.game.GameContext;
import butines.core.game.Image;
import butines.core.game.ImageCursor;
import butines.core.game.ImageSheet;
import butines.core.game.Input;
import butines.core.game.InputListener;
import butines.core.game.Sound;
import butines.game.Sprite;
import butines.game.TileSet;

public class TileSetTest implements Game, InputListener {

	Image image ;
	ImageSheet sheet;
	TileSet tileSet;
	
	ImageSheet footmanSheet;
	
	Unit unit0 = new Unit();
	Unit unit1 = new Unit();
	
	UIWorld world;
	Input input;
	GameContext gameContext;
	
	Sound sound;
	
	public void init(GameContext ctx) {
		
		gameContext = ctx;
		
//		ctx.setResolution(200, 200, false);
		
		input = ctx.getInput();
		input.addListener(this);
			
		Image image = new Image("datas/ui/cursor_arrow.png");
		ctx.setGameCursor(new ImageCursor(image, 5));
		ctx.setVisibleWindowCursor(true);
		
		
		Image footmanImage = new Image("datas/unit/footman.png");
		footmanImage = ImageHelper.createIsometricImage(footmanImage, 8);
		
		UnitTemplate template = new UnitTemplate();
		template.setName("Footman");
//		template.setImageSheet(imageSheet);
		template.setMaxHealth(100);
		template.setMaxForce(1f);
		template.setMaxSpeed(1f);
		template.setMass(1f);
		template.setRadius(12);
		template.setViewDistance(32);
		
		
		unit0.setPosition(70, 70);
		unit0.setSprite(new Sprite(new ImageSheet(footmanImage, 72, 72), 8));
		unit0.getAnimations().getStay().set(false, 0, 0);
		unit0.getAnimations().getWalk().set(true, .7f, 1, 2, 0, 3, 4, 0);

		unit1.setPosition(30, 70);
		unit1.setSprite(new Sprite(new ImageSheet(footmanImage, 72, 72), 8));
		unit1.getAnimations().getStay().set(false, 0, 0);
		unit1.getAnimations().getWalk().set(true, .7f, 1, 2, 0, 3, 4, 0);
		
		world = new UIWorld();
		world.setPosition(0, 0);
		world.setSize(1920, 1080);
		world.init(new ImageSheet(new Image("datas/summer.png"), 32, 32), 60, 34);
		world.getPlayer0().addUnit(unit0);
		world.getPlayer0().addUnit(unit1);
		
		
		ctx.getRoot().add(world);
		
		Globals.debug.setValue(1);
		
		sound = ctx.getAudio().load("datas/voice_select_3.wav");
		sound = ctx.getAudio().load("datas/voice_select_3.wav");
		
	}
	public void destroy() {

	}

	public void update(float tpf) {
		if (input.isKeyDown(Input.KEY_ALT) && input.isKeyDown(Input.KEY_F4)) {
			gameContext.shutdown();
		}
	}
	
	public void render(Graphics2D g) {
		Drawing.clear(Color.BLACK);
		
	}

	public void onKey(int keyCode, boolean pressed, float tpf) {
		
	}
	
	public void onButton(int sx, int sy, int button, boolean pressed, float tpf) {
		if (pressed) {
			sound.play();
		}
	}
	
	public void onMove(int x, int y, int dx, int dy, float tpf) {
	}
	
	public void onWheel(int x, int y, int wheel, float tpf) {
		// TODO Auto-generated method stub
		
	}
	public static void main(String[] args) {
		TileSetTest game = new TileSetTest();
		GameContainer gameContainer = new GameContainer(game);
		gameContainer.setTargetFps(60);
		gameContainer.setResolution(640, 480, false);
		gameContainer.start();
	}

}